package advanced.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatch_L {
    static int count = 200;

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(count);
        ExecutorService service = Executors.newCachedThreadPool();
        for (int i = 0; i < count; i++) {
            int finalI = i;
            service.execute(() -> {
                System.out.println(finalI);
                countDownLatch.countDown();

            });
        }
        try {
            countDownLatch.await();//Causes the current thread to wait until the latch has counted down to zero, unless the thread is
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("all thread running over");
        service.shutdown();

    }
}
